package com.tqy.docms.controller;

import com.tqy.docms.entity.Xw;
import com.tqy.docms.service.XwService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @title: XwController
 * @projectName: docms
 * @description: 新闻 API
 * @author: yuzf
 * @date: 2019/6/28 9:24
 */
@RestController
public class XwController {
    private static final Logger LOG = LoggerFactory.getLogger(XwController.class);

    @Autowired
    private XwService xwService;
    /*
    * 增加新闻
    * */
   @PostMapping("/addxw")
    int addXw(Xw xw){
       int result = xwService.addXw(xw);
       return result;
   }
    /*
    * 删除新闻
    * */
   @GetMapping("/delxw")
    int delXw(String nm){
       int result = xwService.delXw(nm);
       return result;
   }
    /*
    * 修改新闻
    * */
    @PostMapping("/editXw")
    int editXw(Xw  xw){
        int result = xwService.editXw(xw);
        return result;
    }
    /*
    * 获得所有的新闻
    * */
    @GetMapping("/getallXw")
    List<Xw> getallXw(){
        List<Xw> xws = xwService.getallXw();
        return xws;
    }
    /*
    * 获得某条新闻
    * */
    @GetMapping("/getoneXw")
    Xw getoneXw(@RequestParam String nm){

        Xw xw = xwService.getoneXw(nm);
        return xw;
    }
    /*
    * 多条件查询新闻
    * */
    @PostMapping("/selectXw")
    List<Xw> selectXw(Xw xw){
        List<Xw> xws = xwService.selectXw(xw);
        return xws;
    }

}
